﻿@model CNRegex.Web.Models.ModelRegexSearch
@{
	ViewBag.Title = "Search";
}

<link href="@Url.Content("~/Content/css/RegexHomeSearch.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery.cookie.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/common.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.highlight.js")" type="text/javascript"></script>
<script type="text/javascript">

	$(document).ready(
		function () {
			var len = document.getElementById("pagination-flickr").getElementsByTagName("li").length;
			var width = len * 20 + 80;
			$("#pagination-flickr").css("width", width + "px");
			var keywords = jQuery.trim($("#SearchExpression_Keywords").val());
			if (keywords != "") {
				$('#leftContainer').removeHighlight().highlight(keywords);
			}
		}
	);
	function search(order, aId) {
		var keywords = jQuery.trim($("#SearchExpression_Keywords").val());
		var catalogID = $("#SearchExpression_UserExpressionCatalogID").val();
		var direction = "";
		if (aId != undefined) {
			direction = Math.abs(parseInt($("#" + aId).attr("order")) - 1);
			direction = isNaN(direction) ? 1 : direction;
		}
		window.location.href = "/regexhome/search/?c=" + catalogID + "&k=" + escape(keywords) + (order == undefined ? "" : "&ok=" + order) + (aId == undefined ? "" : "&d=" + direction);
	}

	function preserver(index, id) {
		$.ajax({
			type: "POST",
			url: "/regex/preserver",
			data: "id=" + id,
			success: function (msg) {
				if (msg == "login") {
					window.location = "/account/login";
					return;
				}
				$('#aPreserver' + index).attr("href", "javascript:void(0)");
				$('#aPreserver' + index).fadeIn();
				$('#aPreserver' + index).html("");
				$('#aPreserver' + index).removeClass().addClass("rhi_preservered");
			}
		});
	}


</script>

<h2 class="t_h2">
	搜索表达式</h2>
<div class="rhs_right_content">
	
</div>
<div class="rhs_left_content clearLeft" id="leftContainer">
	
	<div class="rhs_search_condition">
		<span class="rhs_span_key">关键字:</span>
		@Html.TextBoxFor(x => x.SearchExpression.Keywords)
		<span class="rhs_span_catalog">分类:</span>
		@Html.DropDownListFor(x => x.SearchExpression.UserExpressionCatalogID, Model.ExpressionCatalog)
		<input type="button" value="搜索" class="rhs_btn_search" onclick="return search();" onkeydown="return searchKeyPress(event);" />
	</div>
	<div class="rhs_order">
		<a href="javascript:search('date','aDate')" id="aDate" @(Model.SearchExpression.OrderCreateDate == null ? "" : string.Format("order={0}", (int)Model.SearchExpression.OrderCreateDate))>时间<span class="rhs_direction">@(Model.SearchExpression.OrderCreateDate == null ? "" : Model.SearchExpression.OrderCreateDate == CNRegex.Enum.EnumOrder.ASC ? "↑" : "↓")</span></a>
		<a href="javascript:search('recommend','aRecommend')" id="aRecommend" @(Model.SearchExpression.OrderRecommend == null ? "" : string.Format("order={0}", (int)Model.SearchExpression.OrderRecommend))>推荐<span class="rhs_direction">@(Model.SearchExpression.OrderRecommend == null ? "" : Model.SearchExpression.OrderRecommend == CNRegex.Enum.EnumOrder.ASC ? "↑" : "↓")</span></a>
		<a href="javascript:search('click','aClick')" id="aClick" @(Model.SearchExpression.OrderClick == null ? "" : string.Format("order={0}", (int)Model.SearchExpression.OrderClick))>点击<span class="rhs_direction">@(Model.SearchExpression.OrderClick == null ? "" : Model.SearchExpression.OrderClick == CNRegex.Enum.EnumOrder.ASC ? "↑" : "↓")</span></a>
	</div>

	<div class="rhs_top_pagination">
		@{
			Html.RenderPartial("/Views/Controls/Paginate.cshtml", Model.ExPaginate);
			int j = 0;
		}
	</div>
	<div class="clear"></div>
	<hr class="rhs_line" />
	<ul class="rhs_expression_list">
		@foreach (var item in Model.Expressiones)
  {

			<li>
				<div class="rhs_upup" onclick="recommend('/regex/recommend','@Model.Expressiones[j].ID','spanRecommendTimes','@j','recommendExpressionCookie','您已经推荐过此表达式,谢谢.')">
					<span @Html.Raw(string.Format("id=spanRecommendTimes{0}", j))>@(Model.Expressiones[j].Recommend == null ? "0" : Model.Expressiones[j].Recommend.Value.ToString())</span>
				</div>
				<div class="rhs_expressionContainer">
					<table>
						<colgroup>
							<col width="9%" />
							<col />
						</colgroup>
						<tr>
							<td class="rhs_tdText">
							</td>
							<td>
								<a href="/RegexHome/Detail/@item.ID" class="rhs_expressionTitle">@item.Title</a>
								<div style="float: right;">
									
									@if (Model.RegexFavourites.FirstOrDefault(x => x.FavoriteID == item.ID) == null)
		 {
										<a href="javascript:preserver(@j,'@item.ID')" class="rhs_preserver" id="aPreserver@(j)">
											收藏</a>
		 }
		 else
		 {
										<a href="javascript:void(0)" class="rhs_preservered"></a>
		 }
									<span class="rhs_byText">By:</span> <a href="/@item.RegexUserName" class="rhs_author" target="_blank">@item.RegexUserName</a>
									，<span class="black">@item.CreateDate.Value.ToString("yyyy/MM/dd")</span>，
									<span class="black">浏览 - <span class="red">@(item.ClickCount==null?0:item.ClickCount)</span> </span>
								</div>
							</td>
						</tr>
						<tr>
							<td class="rhs_tdText">
							</td>
							<td>
								<div class="rhs_expressionContent">@item.Expression</div>
							</td>
						</tr>
						<tr>
							<td class="rhs_tdText">
								描述
							</td>
							<td>
								<div>@item.Description</div>
							</td>
						</tr>
						<tr>
							<td class="rhs_tdText">
								<div class="rhs_txt_matches">
									匹配</div>
							</td>
							<td>
								<div class="rhs_matches">
									<ul>
										@{
		var matches = item.Matches.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);
										}
										@for (int i = 0; i < matches.Length; i++)
		  {
											<li>@matches[i]</li>
		  }
									</ul>
								</div>
							</td>
						</tr>
						<tr>
							<td class="rhs_tdText">
								<div class="rhs_txt_nonmatches">
									不匹配
								</div>
							</td>
							<td>
								<div class="rhs_nonmatches">
									<ul>
										@{
		  var nonMatches = item.NonMatches.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);
										}
										@for (int i = 0; i < nonMatches.Length; i++)
		  {
											<li>@nonMatches[i]</li>
		  }
									</ul>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</li>
		  j++;
  }
	</ul>
</div>
